/////////////////////////////////////////////////////////////////////////
//
// Amuse Engine - graphics/materials
// Copyright (c) 2015.  All Rights Reserved
//
// File:		AEMaterialTextures.inl
// Author:		Gianluca Belardelli
// Date:		20/07/2015
//
/////////////////////////////////////////////////////////////////////////
#ifndef _AEMATERIALTEXTURES_INL_
#define _AEMATERIALTEXTURES_INL_

AE_FORCEINLINE AEMaterialTextures::AEMaterialTextures( void ) : m_vcLightmapScaleOfs(1.0f, 1.0f, 0.0f, 0.0f)
{
	m_nIndex = 0;
	m_spAuxiliaryTextures = AENULL;
	m_sAuxiliaryTextureCount = 0;
}

AE_FORCEINLINE AEMaterialTextures::~AEMaterialTextures( void )
{
	AE_SAFE_DELETE_ARRAY( m_spAuxiliaryTextures );
}

AE_FORCEINLINE const char *AEMaterialTextures::GetBaseTexture( void ) const
{
	if( m_spDiffuseTexture )
		return m_spDiffuseTexture->GetOriginalFilename();

	return AENULL;
}

AE_FORCEINLINE const char *AEMaterialTextures::GetNormalMapTexture( void ) const
{
	if( m_spNormalMap )
		return m_spNormalMap->GetOriginalFilename();

	return AENULL;
}

AE_FORCEINLINE const char *AEMaterialTextures::GetSpecularMapTexture( void ) const
{
	if( m_spSpecularMap )
		return m_spSpecularMap->GetOriginalFilename();

	return AENULL;
}

AE_FORCEINLINE AETexture *AEMaterialTextures::GetBaseTextureObject( void ) const
{
	return m_spDiffuseTexture;
}

AE_FORCEINLINE AETexture *AEMaterialTextures::GetNormalMapTextureObject( void ) const
{
	return m_spNormalMap;
}

AE_FORCEINLINE AETexture *AEMaterialTextures::GetSpecularMapTextureObject( void ) const
{
	return m_spSpecularMap;
}

AE_FORCEINLINE AEINT32 AEMaterialTextures::GetAuxiliaryTextureCount( void ) const
{
	return m_sAuxiliaryTextureCount;
}

AE_FORCEINLINE AETexture *AEMaterialTextures::GetAuxiliaryTexture( AEINT32 nIndex ) const
{
	AEASSERT( m_spAuxiliaryTextures != AENULL && nIndex>=0 && nIndex<m_sAuxiliaryTextureCount );
	return m_spAuxiliaryTextures[nIndex];
}

AE_FORCEINLINE void AEMaterialTextures::SetAuxiliaryTexture( AEINT32 nIndex, AETexture *lpTexture ) const
{
	AEASSERT( m_spAuxiliaryTextures!=AENULL && nIndex>=0 && nIndex<m_sAuxiliaryTextureCount );
	m_spAuxiliaryTextures[nIndex] = lpTexture;
}

AE_FORCEINLINE AEMaterialTextures &AEMaterialTextures::operator = ( const AEMaterialTextures &refOther )
{
	if( this == &refOther )
		return *this;

	m_nIndex = refOther.m_nIndex;
	m_spDiffuseTexture = refOther.m_spDiffuseTexture;
	m_spNormalMap = refOther.m_spNormalMap;
	m_spSpecularMap = refOther.m_spSpecularMap;
	m_spModelLightmaps[0] = refOther.m_spModelLightmaps[0];
	m_spModelLightmaps[1] = refOther.m_spModelLightmaps[1];
	m_spModelLightmaps[2] = refOther.m_spModelLightmaps[2];
	m_spModelLightmaps[3] = refOther.m_spModelLightmaps[3];
	m_vcLightmapScaleOfs = refOther.m_vcLightmapScaleOfs;

	//copy auxiliary textures
	AE_SAFE_DELETE_ARRAY( m_spAuxiliaryTextures );
	m_sAuxiliaryTextureCount = refOther.m_sAuxiliaryTextureCount;
	if( m_sAuxiliaryTextureCount>0 )
	{
		AEINT32 i;
		m_spAuxiliaryTextures = new AETexturePtr[m_sAuxiliaryTextureCount];

		for( i=0; i<m_sAuxiliaryTextureCount; i++ )
			m_spAuxiliaryTextures[i] = refOther.m_spAuxiliaryTextures[i];
	}

	return *this;
}

AE_FORCEINLINE AEINT32 AEMaterialTextures::GetIndex( void ) const
{
	return m_nIndex;
}

AE_FORCEINLINE void AEMaterialTextures::SetIndex( AEINT32 nIndex )
{
	m_nIndex=nIndex;
}

#endif // _AEMATERIALTEXTURES_INL_
